---
description: "Reference for Nitric's v0 JVM library - Send tasks to a queue."
---

# JVM - queue.send()

Send tasks to a queue.

<Tabs syncKey="jvm-lang">

<TabItem label="Java">

```java
import io.nitric.Nitric;
import io.nitric.resources.QueuePermission;

public class Application {
  public static void main(String[] args) {
    var queue = Nitric.INSTANCE.queue("batch").with(QueuePermission.Send);

    var payload = Map.of("message", "hello");
    queue.send(payload);

    Nitric.INSTANCE.run();
  }
}
```

</TabItem>

<TabItem label="Kotlin">

```kotlin
import io.nitric.Nitric
import io.nitric.resources.QueuePermission

fun main() {
  val queue = Nitric.queue("batch").with(QueuePermission.Send)

  var payload = mapOf("message" to "hello")
  queue.send(payload)

  Nitric.run()
}
```

</TabItem>

</Tabs>

## Parameters

<Properties>
  <Property name="tasks" required type="Task or List<Task>">
    A task or an array of tasks to send to the queue.
  </Property>
</Properties>

## Examples

### Send a task to a queue

<Tabs syncKey="jvm-lang">

<TabItem label="Java">

```java
import io.nitric.Nitric;
import io.nitric.resources.QueuePermission;

public class Application {
  public static void main(String[] args) {
    var queue = Nitric.INSTANCE.queue("batch").with(QueuePermission.Send);

    var payload = Map.of("message", "payloads can be any serializable object");
    queue.send(payload);

    Nitric.INSTANCE.run();
  }
}
```

</TabItem>

<TabItem label="Kotlin">

```kotlin
import io.nitric.Nitric
import io.nitric.resources.QueuePermission

fun main() {
  val queue = Nitric.queue("batch").with(QueuePermission.Send)

  var payload = mapOf("message" to "payloads can be any serializable object")
  queue.send(payload)

  Nitric.run()
}
```

</TabItem>

</Tabs>

### Send multiple tasks to a queue

<Tabs syncKey="jvm-lang">

<TabItem label="Java">

```java
import io.nitric.Nitric;
import io.nitric.resources.QueuePermission;

import java.util.List;

public class Application {
  public static void main(String[] args) {
    var queue = Nitric.INSTANCE.queue("batch").with(QueuePermission.Send);

    var payloads = List.of(
      Map.of(
        "type", "SMS",
        "to", "+172000000000",
        "subject", "Notification",
        "message", "A text message from Nitric"
      ),
      Map.of(
        "type", "Email",
        "to", "hello@example.com",
        "subject", "Notification",
        "message", "A notification from Nitric",
      )
    );
    queue.send(payloads);

    Nitric.INSTANCE.run();
  }
}
```

</TabItem>

<TabItem label="Kotlin">

```kotlin
import io.nitric.Nitric
import io.nitric.resources.QueuePermission

fun main() {
  val queue = Nitric.queue("batch").with(QueuePermission.Send)

  var payloads = listOf(
    mapOf(
      "type" to "SMS",
      "to" to "+172000000000",
      "subject" to "Notification",
      "message" to "A text message from Nitric"
    ),
    mapOf(
      "type" to "Email",
      "to" to "hello@example.com",
      "subject" to "Notification",
      "message" to "A notification from Nitric",
    )
  )
  queue.send(payload)

  Nitric.run()
}
```

</TabItem>

</Tabs>

### Dealing with failures

In rare cases when sending tasks to a queue some tasks might fail to be sent. The response from `send()` will include an array of any tasks that failed to send. You can process this array to retry or log the error.

<Tabs syncKey="jvm-lang">

<TabItem label="Java">

```java
var failed = queue.send(tasks);

failed.forEach((task) -> {
  System.out.println(task);
});
```

</TabItem>

<TabItem label="Kotlin">

```kotlin
val failed = queue.send(tasks)

failed.forEach { task ->
  println(task)
}
```

</TabItem>

</Tabs>
